package com.dson.controller;

import com.dson.api.Student2Service;
import com.dson.api.StudentService;
import com.dson.api.TeacherService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@RestController
public class WebController {
    private ExecutorService executorService = new ThreadPoolExecutor(100,200,5, TimeUnit.SECONDS,new LinkedBlockingDeque<>(3000));

    @DubboReference
    private StudentService studentService;

    @DubboReference
    private Student2Service student2Service;

    @DubboReference
    private TeacherService teacherService;

    @GetMapping(value = "/learn")
    public String learn(String name){
        studentService.learn(name);
        student2Service.learn2(name);
        return "learn success";
    }

    @GetMapping(value = "/work")
    public String work(Integer size){

        for (int i = 0;i<=size;i++){

            executorService.execute(()->{
                teacherService.methodA();
                teacherService.methodB();
                teacherService.methodC();
            });
        }
        return "success";
    }
}
